package com.hang.mapstruct;

import com.hang.entity.Bug;
import com.hang.model.dto.request.BugModelReq;
import com.hang.model.vo.BugInfoDetailVO;
import com.hang.model.vo.BugInfoVO;
import com.hang.model.vo.BugInfoVOList;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.LinkedList;
import java.util.List;

@Mapper(componentModel = "spring")
public interface BugMapStruct {
    Bug bugModelReqToBug(BugModelReq bugModelReq);

    default List<BugInfoVO> bugListToBugInfoVOList(List<Bug> bugList){
        List<BugInfoVO> bugInfoVOList = new LinkedList<>();
        bugList.forEach(
                bug -> {
                    bugInfoVOList.add(bugToBugInfoVO(bug));
                }
        );

        return bugInfoVOList;
    }

    @Mapping(source = "bugId",target = "bugId")
    @Mapping(source = "bugType",target = "bugType",qualifiedByName = "typeFormatter")
    @Mapping(source = "priority",target = "priority",qualifiedByName = "priorityFormatter")
    @Mapping(source = "severity",target = "severity",qualifiedByName = "severityFormatter")
    @Mapping(source = "solveStatus",target = "solveStatus",qualifiedByName = "statusFormatter")
    BugInfoVO bugToBugInfoVO(Bug bug);

    @Mapping(source = "bugId",target = "bugId")
    @Mapping(source = "bugType",target = "bugType",qualifiedByName = "typeFormatter")
    @Mapping(source = "priority",target = "priority",qualifiedByName = "priorityFormatter")
    @Mapping(source = "severity",target = "severity",qualifiedByName = "severityFormatter")
    @Mapping(source = "solveStatus",target = "solveStatus",qualifiedByName = "statusFormatter")
    BugInfoDetailVO bugToBugInfoDetailVO(Bug dbBug);

    @Named("typeFormatter")
    default String typeFormatter(Integer bugType){
        if(bugType.compareTo(1) == 0){
            return "线上问题";
        }else if(bugType.compareTo(2) == 0){
            return "功能缺陷";
        }else if(bugType.compareTo(3) == 0){
            return "需求问题";
        }else if(bugType.compareTo(4) == 0){
            return "性能瓶颈";
        }else if(bugType.compareTo(5) == 0){
            return "反馈意见";
        }

        return "全部";
    }

    @Named("priorityFormatter")
    default String priorityFormatter(Integer priority){
        if(priority.compareTo(1) == 0){
            return "低";
        }else if(priority.compareTo(2) == 0){
            return "中";
        }else if(priority.compareTo(3) == 0){
            return "高";
        }else if(priority.compareTo(4) == 0){
            return "紧急";
        }

        return "全部";
    }

    @Named("statusFormatter")
    default String statusFormatter(Integer solveStatus){
        if(solveStatus.compareTo(1) == 0){
            return "未处理";
        }else if(solveStatus.compareTo(2) == 0){
            return "处理中";
        }else if(solveStatus.compareTo(3) == 0){
            return "已完成";
        }

        return "全部";
    }

    @Named("severityFormatter")
    default String severityFormatter(Integer severity){
        if(severity.compareTo(1) == 0){
            return "不重要";
        }else if(severity.compareTo(2) == 0){
            return "一般";
        }else if(severity.compareTo(3) == 0){
            return "重要";
        }else if(severity.compareTo(4) == 0){
            return "致命";
        }

        return "全部";
    }
}
